<?
	$dom = $this->dom;
	global $domdata;
?>
	
	function flagChange(){
		$('changesbutton').disabled = false;
		window.onbeforeunload = function(e){
		  var s = 'You have unsaved changes.';
		  if (e) e.returnValue = s;
		  return s;
		};
	}
	
	function unflagChange(){
		$('changesbutton').disabled = true;
		window.onbeforeunload = function(){}
	}
		
	var Domain = {
		load:function(o){
			for(var k in o) this[k] = o[k];
		},
		save:function(){
			var args = {id:this.id, own:this.own, grp:this.grp};
			args.ini = $('domini').value.trim();
			Smajax.exec('saveDomain', args);
			unflagChange()
		}
	};
	
	var Users = {
		change:function(id, usr){
			Domain.own = id;
			$('domown').innerHTML = usr.name;
			flagChange()
		},
		browse:function(){
			Browser.goto('../users', {title:'Change owner of ' + Domain.name + ' to:'});
			AppsB.clickHandler = function(){
				Users.change(this.id, this);
				Browser.hide();
			}
		}
	};
	
	var Groups = {
		change:function(id, grp){
			Domain.grp = id;
			$('domgrp').innerHTML = grp.name;
			flagChange()
		},
		browse:function(){
			Browser.goto('../groups', {title:'Change group of ' + Domain.name + ' to:'});
			AppsB.clickHandler = function(){
				Groups.change(this.id, this);
				Browser.hide();
			}
		}
	};

	window.onload = function(){
		Chrome.load({
			Selection:0
		});
		Domain.load(<?=json_encode($domdata)?>);
		$('domini').value = Domain.ini
	}